/*
 * TileLayer.h
 *
 *  Created on: 10/11/2011
 *      Author: Tales
 */

#ifndef _YEP_ENTITIES_TILELAYER_HPP
#define _YEP_ENTITIES_TILELAYER_HPP

#include "../framework/DrawHandler.hpp"
#include "../video/Tilemap.hpp"
#include "../framework/Entity.hpp"

namespace yep
{
class Tileset;
class Tilemap;

/**
 * A tilemap entity.
 *
 * It works as a adaptor to the Tilemap class, adding the requirements from the DrawHandler.
 */
class TileLayer: public Entity, public DrawHandler
{
public:
	TileLayer();
	TileLayer(Tileset &tileset, unsigned mapWidth, unsigned mapHeight);
//	template<class T>
//	TileLayer(Tileset &tileset, unsigned mapWidth, T iteratorBegin, T iteratorEnd) :
//			_tilemap(tileset, mapWidth, iteratorBegin, iteratorEnd)
//	{
//	}
	TileLayer(const initializer_list<int> &list);
	virtual ~TileLayer();

	/**
	 * @brief Get/Set the tile at given position
	 **/
	int &operator[](size_t index)
	{
		return _tilemap[index];
	}
	/**
	 * @brief Returns the tileWidth
	 **/
	unsigned getMapWidth() const
	{
		return _tilemap.getMapWidth();
	}

	/**
	 * @brief Returns the mapHeigtht
	 **/
	unsigned getMapHeight() const
	{
		return _tilemap.getMapHeight();
	}

	/**
	 * @brief Returns the tileset
	 **/
	Tileset & getTileset() const
	{
		return _tilemap.getTileset();
	}

	/**
	 * @brief Sets the map width.
	 *
	 * Can be called only once, after the default constructor or initilizer_list constructor.
	 **/
	TileLayer & setMapWidth(unsigned value)
	{
		_tilemap.setMapWidth(value);
		return *this;
	}

	/**
	 * @brief Sets the map height
	 *
	 * Can be called only once, after the default constructor or initilizer_list constructor.
	 **/
	TileLayer & setMapHeight(unsigned value)
	{
		_tilemap.setMapHeight(value);
		return *this;
	}

	/**
	 * @brief Sets the tileset.
	 *
	 * Can be called only once, after the default constructor or initilizer_list constructor.
	 **/
	TileLayer & setTileset(Tileset & value)
	{
		_tilemap.setTileset(value);
		return *this;
	}

	double getDepth();

	Vector2 getPosition() const;

	Vector2 getSize() const;

	Tilemap getTilemap() const;

	void setDepth(double depth);

	void setPosition(Vector2 position);

	void setSize(Vector2 size);

	void setTilemap(Tilemap tilemap);

	Vector2 getTopLeft()
	{
		return getPosition();
	}

	Vector2 getBottomRight()
	{
		return getPosition() + getSize();
	}

	void evCreate(Event &event);

	void evDestroy(Event &event);

	void evDraw(DrawEvent &drawEvent);
private:
	Tilemap _tilemap;
	double _depth;
	Vector2 _position;
	Vector2 _size;
};

}

/* namespace yep */
#endif /* _YEP_ENTITIES_TILELAYER_HPP */
